package com.nbicc.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName:
 * @Author: 仄言in
 * @Desctiption: (描述)：登录拦截器
 * @Date: 2021/5/13 9:51
 * @Version 1.0 (版本)
 */
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object u = request.getSession().getAttribute("u");
        if (u == null) {
            request.setAttribute("msg","请先登录！");
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }
        return true;
    }
}
